lib/repo-refs: Add a flag to exclude listing from refs/mirrors
authorMatthew Leeds <matthew.leeds@endlessm.com>
Thu, 21 Feb 2019 23:39:45 +0000 (15:39 -0800)
committerAtomic Bot <atomic-devel@projectatomic.io>
Mon, 15 Apr 2019 15:56:40 +0000 (15:56 +0000)
Currently the flag OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES for
ostree_repo_list_collection_refs() means that refs in refs/remotes/
should be excluded but refs in refs/mirrors/ should still be checked, in
addition to refs/heads/ which is always checked. However in some
situations you want to exclude both remote and mirrored refs and only
check local "owned" ones. So this
commit adds a new flag OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_MIRRORS which
lets you exclude refs/mirrors/ from the listing.

This way we can avoid breaking API but still allow the listing of local
collection-refs.

The impetus for this change is that I'm changing Flatpak to make more
use of refs/mirrors, and we need a way to specify that a collection-ref
is local when using ostree_repo_resolve_collection_ref() in, for
example, the implementation of the repo command. The subsequent commit
will make the changes needed there.

Closes: #1825
Approved by: jlebon

src/libostree/ostree-repo-refs.c
src/libostree/ostree-repo.h

index be2eb59aac8a1645567c885a4811781519fe5ac7..fec36420c9a0bbbaab25bf0b05a2b5a0ddbb8849 100644 (file)
@@ -1247,7 +1247,9 @@ _ostree_repo_update_collection_refs (OstreeRepo        *self,
  * (ostree_repo_get_collection_id()).
  *
  * If you want to exclude refs from `refs/remotes`, use
- * %OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES in @flags.
+ * %OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES in @flags. Similarly use
+ * %OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_MIRRORS to exclude refs from
+ * `refs/mirrors`.
  *
  * Returns: %TRUE on success, %FALSE otherwise
  * Since: 2018.6
@@ -1269,9 +1271,12 @@ ostree_repo_list_collection_refs (OstreeRepo                 *self,
   if (match_collection_id != NULL && !ostree_validate_collection_id (match_collection_id, error))
     return FALSE;
 
-  const gchar *refs_dirs[] = { "refs/mirrors", "refs/remotes", NULL };
-  if (flags & OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES)
-    refs_dirs[1] = NULL;
+  g_autoptr(GPtrArray) refs_dirs = g_ptr_array_new ();
+  if (!(flags & OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_MIRRORS))
+    g_ptr_array_add (refs_dirs, "refs/mirrors");
+  if (!(flags & OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES))
+    g_ptr_array_add (refs_dirs, "refs/remotes");
+  g_ptr_array_add (refs_dirs, NULL);
 
   g_autoptr(GHashTable) ret_all_refs = NULL;
 
@@ -1301,7 +1306,7 @@ ostree_repo_list_collection_refs (OstreeRepo                 *self,
 
   g_string_truncate (base_path, 0);
 
-  for (const char **iter = refs_dirs; iter && *iter; iter++)
+  for (const char **iter = (const char **)refs_dirs->pdata; iter && *iter; iter++)
     {
       const char *refs_dir = *iter;
       gboolean refs_dir_exists = FALSE;
index 7eb983cfa0e0bd0e0430941f8b7aa6e5cdb47c0c..d24077c94b1ef2caf2c337e8ed8086c8217cb264 100644 (file)
@@ -499,11 +499,13 @@ gboolean      ostree_repo_list_refs (OstreeRepo       *self,
  * @OSTREE_REPO_LIST_REFS_EXT_NONE: No flags.
  * @OSTREE_REPO_LIST_REFS_EXT_ALIASES: Only list aliases.  Since: 2017.10
  * @OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES: Exclude remote refs.  Since: 2017.11
+ * @OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_MIRRORS: Exclude mirrored refs.  Since: 2019.2
  */
 typedef enum {
   OSTREE_REPO_LIST_REFS_EXT_NONE = 0,
   OSTREE_REPO_LIST_REFS_EXT_ALIASES = (1 << 0),
   OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES = (1 << 1),
+  OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_MIRRORS = (1 << 2),
 } OstreeRepoListRefsExtFlags;
 
 _OSTREE_PUBLIC